import { createApp, reactive, getCurrentInstance } from 'vue';
let uid = 10010
export function useNotifyState () {
  const state = reactive({
    show: false
  });

  const open = () => {
    state.show = true
  };

  const close = () => {
    state.show = false
  };

  const instance = getCurrentInstance()
  instance && Object.assign(instance.proxy, { open, close });

  return {
    open,
    close,
    state
  };
}

export function mountComponent (rootComponent) {
  const app = createApp(rootComponent);
  const root = document.createElement('div');
  root.className = 'notify__' + uid++
  document.body.appendChild(root);

  return {
    instance: app.mount(root),
    unmount () {
      app.unmount();
      document.body.removeChild(root);
    },
  };
}
